define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cate/index' + location.search,
                    add_url: 'cate/add',
                    edit_url: 'cate/edit',
                    del_url: 'cate/del',
                    multi_url: 'cate/multi',
                    import_url: 'cate/import',
                    table: 'cate',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                escape:false,
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pagination: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'pid', title: __('Pid')},
                        {field: 'name', title: __('Name'), operate: 'LIKE',cellStyle: function (value, row, index) {
                                return {css: {"float": "left"}};

                            }},

                        {field: 'sub_name', title: __('子标题')},
                        {field: 'sort', title: __('排序')},

                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //   {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'status', title: __('Status'), searchList: {"30":__('Status 30')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'video',
                                    text: '视频管理',
                                    title: '视频管理',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-video-camera',
                                    url: function (row) {
                                        return 'video/index?cate_id=' + row.id;
                                    },
                                    visible: function (row) {
                                        return [6, 11, 16].indexOf(parseInt(row.id, 10)) !== -1;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
